package com.example.labapp;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.LinkedList;

public class menuAdapter extends BaseAdapter {
    private LinkedList<menuItem> mData;
    private Context mContext;

    public menuAdapter(LinkedList<menuItem> mData,Context mContext)
    {
        this.mData=mData;
        this.mContext=mContext;
    }
    @Override
    public int getCount()
    {return mData.size();}

    @Override
    public Object getItem(int position)
    {return null;}

    @Override
    public long getItemId(int position)
    {return position;}

    class holdView
    {
        public ImageView img;
        public TextView txt;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        holdView holder=null;
        if(convertView==null)
        {
            convertView= LayoutInflater.from(mContext).inflate(R.layout.main_item_lay2,parent,false);
            holder=new holdView();
            holder.img=convertView.findViewById(R.id.imgItem);
            holder.txt=convertView.findViewById(R.id.txtItem);
            convertView.setTag(holder);
        }
        else
        {
            holder=(holdView) convertView.getTag();
        }
        holder.img.setBackgroundResource(mData.get(position).getImgIcon());
        holder.txt.setText(mData.get(position).getTitle());
        return convertView;
    }
}
